package com.yunfeng.supercall.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.tsz.afinal.FinalBitmap;

import org.json.JSONException;
import org.json.JSONObject;

import com.lin.utils.Parameters;
import com.lin.utils.Utils;
import com.yunfeng.supercall.bean.Constants;

import android.app.IntentService;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;

public class HandlePhoneDataIntentService extends IntentService {
	public static boolean isHandlePhoneDataIntentServiceRunning = false;
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
	}

	public HandlePhoneDataIntentService() {
		// TODO Auto-generated constructor stub
		super("HelloIntentService");
	}

	public HandlePhoneDataIntentService(String name) {
		super(name);
		// TODO Auto-generated constructor stub
	}

	protected void onHandleIntent(Intent intent) {
		isHandlePhoneDataIntentServiceRunning = true;
		new Thread(runnable).start();
	}

	Runnable runnable = new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			try {
			Parameters.mArrayListPhoneContactsBean =  Utils.getPeopleInPhone2(getApplicationContext());
			Collections.sort(Parameters.mArrayListPhoneContactsBean);
			mHandler.sendEmptyMessage(0);
			} catch(Exception e) {
				
			}

		}

	};

	Handler mHandler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			super.handleMessage(msg);
			sendBroadcast(new Intent(Constants.ACTION_UPDATE_PHONE));
			stopSelf();
			isHandlePhoneDataIntentServiceRunning = false;
		}

	};

}